/******************************************************************************
 *  Copyright © 2019 Shenzhen ECIOT Technology Co., Ltd All Rights Reserved
 *-----------------------------------------------------------------------------
 * @file        ec_app_ble.c
 * @brief       ble control
 * @author      mo@eciot.cn (qq:2201920828,v:eciot_mo)
 * @date        2022-02-13
 * @version     1.0
 ******************************************************************************/

#include "ec_core.h"
#include "ec_app_ble_peripheral.h"

void ec_app_ble_param_init(void) //蓝牙参数初始化
{
	/*
     ec_core_ble_set_power(EC_CORE_BLE_POWER_10DBM);//配置发射功率，默认3dbm

    // 配置UUID
    // 16bit uuid
    // ec_core_ble_set_suuid("FFF0");
    // ec_core_ble_set_ruuid("FFF1");
    // ec_core_ble_set_wuuid("FFF2");
    // 128bit uuid
     ec_core_ble_set_suuid("49535343-FE7D-4AE5-8FA9-9FAFD205E477");
     ec_core_ble_set_ruuid("49535343-1E4D-4BD9-BA61-23C647249677");
     ec_core_ble_set_wuuid("49535343-8841-43F4-A8D4-ECBE34729B77");

    ec_core_ble_peripheral_set_ota_en(ec_app_ble_peripheral_ota_en); //打开或关闭OTA升级

    uint8_t mac[6] = {0xC5,0xD4,0x7F,0x44,0x26,0x08};
//    ec_core_ble_get_mac(mac); //获取MAC地址
    char buf[] = {0};
		
		ec_core_ble_set_mac(mac);
    sprintf(buf, "HYPC5D47F442608");
		
    ec_core_ble_peripheral_set_name((uint8_t *)buf, sizeof(buf)); //根据MAC地址修改蓝牙名字
    // ec_core_ble_peripheral_set_name("BT_123", strlen("BT_123"));
		 uint8_t data1[31] = {0xC5,0xD4,0x7F,0x44,0x26,0x08};
				 uint8_t data2[31] = {0xC5,0xD4,0x7F,0x44,0x26,0x08};
		ec_core_ble_peripheral_reset_adv();     
//		ec_core_ble_peripheral_set_custom_adv_data(data1,6);
//		ec_core_ble_peripheral_set_custom_scan_rsp(data2,6);
    ec_app_ble_peripheral_register_event(); //注册蓝牙回调
		
		*/
		
		    // ec_core_ble_set_power(EC_CORE_BLE_POWER_3DBM);//配置发射功率，默认3dbm

    // 配置UUID
    // 16bit uuid
    // ec_core_ble_set_suuid("FFF0");
    // ec_core_ble_set_ruuid("FFF1");
    // ec_core_ble_set_wuuid("FFF2");
    // 128bit uuid
    // ec_core_ble_set_suuid("53527AA4-29F7-AE11-4E74-997334782568");
    // ec_core_ble_set_ruuid("654B749C-E37F-AE1F-EBAB-40CA133E3690");
    // ec_core_ble_set_wuuid("EE684B1A-1E9B-ED3E-EE55-F894667E92AC");
		 ec_core_ble_set_suuid("49535343-FE7D-4AE5-8FA9-9FAFD205E477");
     ec_core_ble_set_ruuid("49535343-1E4D-4BD9-BA61-23C647249677");
     ec_core_ble_set_wuuid("49535343-8841-43F4-A8D4-ECBE34729B77");

    ec_core_ble_peripheral_set_ota_en(ec_app_ble_peripheral_ota_en); //打开或关闭OTA升级

    uint8_t mac[6] = {0xC5,0xD4,0x7F,0x44,0x26,0x08};
    ec_core_ble_set_mac(mac); //获取MAC地址
//    char buf[25] = {0};
//    sprintf(buf, "HYP_%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
//    ec_core_ble_peripheral_set_name((uint8_t *)buf, 16); //根据MAC地址修改蓝牙名字
    // ec_core_ble_peripheral_set_name("BT_123", strlen("BT_123"));
		 uint8_t data1[] = {
    0x02, 0x01, 0x06,      // ble flag
		0x11, 0x09, 0x48,0x59,0x50,0x5F,0x43,0x35,0x44,0x34,0x37,0x46,0x34,0x34,0x32,0x36,0x30,0x38
		 } ;
		 
		 uint8_t scan_rsp[] = {
0x11, 0x07,0x77, 0xE4, 0x05, 0xD2, 0xAF, 0x9F, 0xA9, 0x8F, 0xE5, 0x4A, 0x7D, 0xFE, 0x43, 0x53, 0x53, 0x49
};
		 
//				 uint8_t data1[] = {0x17,0x09,0x48,0x59,0x50,0x5F,0x43,0x35,0x44,0x34,0x37,0x46,0x34,0x34,0x32,0x36,0x30,0x38};
//				 uint8_t data2[] = {0x10,0x77,0x7E,0x40,0x5D,0x2A,0xF9,0xFA,0x98,0xFE,0x54,0xA7,0xDF,0xE4,0x35,0x35};

		ec_core_ble_peripheral_set_custom_adv_data(data1,sizeof(data1));
		ec_core_ble_peripheral_set_custom_scan_rsp(scan_rsp,sizeof(scan_rsp));

    ec_app_ble_peripheral_register_event(); //注册蓝牙回调

		
		
}
